package ParallelMachineArrangeImpl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

//3.2 总完工时间问题-SPT算法（Shortest Processing Time First）
public class _3_2_SPT extends ParallelMachineArrange{

    @Override
    public void solve() {
        artifacts = new ArrayList<>();
        if(process==null) {
            process = new int[]{1, 1, 2, 3, 5, 6, 6, 8};
            for (int p : process) {
                Artifact a = new Artifact();
                a.process = p;
                a.remain_process = p;
                artifacts.add(a);
            }
        }
        artifacts.sort(Comparator.comparingInt(o -> o.process));
        List<List<Artifact>> machine_list = new ArrayList<>();
        for(int i=0;i<machines;i++){
            machine_list.add(new ArrayList<>());
        }
        for (int i = 0; i < artifacts.size(); i++) {
            Artifact a = artifacts.get(i);
            machine_list.get(i%machines).add(a);
        }
        int tt = 0;
        System.out.println("最优排序：");
        for (List<Artifact> artifactList : machine_list) {
            tt += getTotalCompleteTime(artifactList);
            System.out.println(artifactList);
        }
        System.out.println("用时" + tt);
    }
}
